<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/peizhi.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="${ctx}">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        
        <title>后台管理中心</title> 
		<link rel="stylesheet" href="${ctx}/css/pintuer.css" /> 
		<link rel="stylesheet" href="${ctx}/css/admin.css" /> 
        <script type="text/javascript" src="${ctx}/js/jquery-1.9.1.min.js"></script>
    </head>
  	<body style="background-color:#f2f9fd;"> 
	  <jsp:include page="include/header.jsp" flush="true"/>
  <div class="admin"> 
  	<div class="panel admin-panel">
	  <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong></div>
	  <div class="padding border-bottom">  
	  <button type="button" class="button border-yellow" onclick="window.location.href='#add'"><span class="icon-plus-square-o"></span> 添加内容</button>
	  </div>
	  <table id='pagehtml' class="table table-hover text-center">
	    
	  </table>
	</div>
	<form id="pageForm" action="${ctx}/activity/getListActivity">
		<input type="hidden" name="pageNo" id="pageNo" value="0" /> 
		<input type="hidden" name="pageSize" id="pageSize" value="10" /> 
		<input id='lastPage' type="hidden">
	</form>
	<script type="text/javascript">
	function del(id,mid){
		if(confirm("您确定要删除吗?")){
		
		}
	}
	</script>
   <!-- <iframe scrolling="auto" rameborder="0" src="info.jsp" name="right" width="100%" height="100%"></iframe>  -->
  </div> 
 </body>
 <script type="text/javascript">
	page(1,2);
	function page(ct,size,t){
		var last = $('#lastPage').val();
		if(t=='prev'){
			ct = Number($('#pageNo').val())-1;
		}
		if(t=='next'){
			ct = Number($('#pageNo').val())+1;
		}
		if(t=='search'){
			ct = Number($('#lastPage').val());
		}
		if(ct!=1){
			if(ct<0||ct>last){return ;}//如果不在包含的页数则不变
		}
		$('#pageNo').val(ct);
		$('#pageSize').val(size);
		$.ajax({
			url:$('#pageForm').attr('action'),
			type:"post",
			data:$('#pageForm').serialize(),
			success:function(data){
				var list = data.list;
				var html='';
				for (var i = 0; i < list.length; i++) {
					html = html + pageAppend(list[i]);
				}
				html = listhead + html;
				html = html + data.html;
				$("#pagehtml").html(html);
				$('#lastPage').val(data.countpage);
				
				/* $("#searchInput").click(function(){
					alert("尾页");
				}); */
			}
		});  
	}
	var listhead='<tr>'+
	      '<th width="15%">名称</th>'+
	      '<th width="20%">图片</th>'+
	      '<th width="20%">描述</th>'+
	      '<th width="10%">排序</th>'+
	     ' <th width="15%">操作</th>'+
	    	'</tr>';
	var listhtml = "<tr>";
		  listhtml = listhtml + "<td>{0}</td>";
	      listhtml = listhtml + "<td><img src='${ctx}/images/{1}' alt='' width='120' height='50' /></td>";     
	      listhtml = listhtml + "<td>{2}</td>";
	      listhtml = listhtml + "<td>{3}</td>";
	      listhtml = listhtml + "<td><div class='button-group'>";
	      listhtml = listhtml + "<a class='button border-main' href='#add'><span class='icon-edit'></span> 修改</a>";
	      listhtml = listhtml + "<a class='button border-red' href='javascript:void(0)' onclick='del({4})'><span class='icon-trash-o'></span> 删除</a>";
	      listhtml = listhtml + "</div></td>";
		  listhtml = listhtml + "</tr>";
	function pageAppend(data){
		return listhtml.replace('{0}',data.title)
		.replace('{1}',data.headimg)
		.replace('{2}',data.contents)
		.replace('{3}',data.keyword)
		.replace('{4}',data.id);
	}
	function pageGo(size){
		var last = $("#last").val();
		if(last!=''){
			page(last,size);
		}else{
			alert("选页框不可为空");
		}
		
	}
</script>
</html>